﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ChoiceUserGroupInfo.aspx.cs" Inherits="SysManage_ChoiceUserGroupInfo" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>组织信息选择</title>
    <link rel="stylesheet" href = "SysManage.CSS" type="text/css" />
    <script language ="javascript" type="text/javascript" >
    <!--
function ck(obj,obj1){
if(obj.lowsrc=="") return true;
obj.imgRolln=obj.src;
obj.src=obj.lowsrc;
obj.lowsrc=obj.imgRolln;
if(obj1.style.display=='none')
   obj1.style.display='';
else
   obj1.style.display='none';
}

var GOrgInfo = "" ;
var GNextOrgID = "";      //本级及下级部门ID集合
var GNoRepeatOrgID = "";  //得到本级及下级不重复部门ID集合
//显示树型
function show_tree(space_c,ParentID)
{
  var i,j,k,img_src1,img_src2; 
  for(k=0;k<trees.length;k++)
  {
    if(trees[k].ParentID == ParentID)
    {      
      document.write("<table border=0 cellspacing=0 cellpadding=0 bordercolor=#000000 width=100%><tr><td>");      
      for(i=1;i<=space_c;i++)
        document.write("&nbsp;&nbsp;");
      if(GOrgInfo!="")
      {
        if(trees[k].ID != ParentID)
        {
           img_src1="img/sys/close.gif";
           img_src2="img/sys/open.gif";
        } 
        var ary  = GOrgInfo.split(',');
        var nary = ary.length;
        for(i=0;i<nary-1;i++)
        {
          if(trees[k].ID == ary[i])
          {
            img_src1="img/sys/open.gif";
            img_src2="img/sys/close.gif";
          }
          if(trees[k].ParentID == ary[i])
          {
             img_src1="img/sys/close.gif";
             img_src2="img/sys/open.gif";
           }             
        }
        
      }
      else
      {
           img_src1="img/sys/close.gif";           
           img_src2="img/sys/open.gif";           
      }
      
      if(trees[k].ChildNumber=="0")
      {
        img_src1="img/sys/open.gif";
        img_src2="img/sys/open.gif";
      }
      document.write("<img lowsrc=" + img_src2 + " id=\"img_"+trees[k].ID+"\" onclick=\"ck(this,document.all.T" + trees[k].ID + ");\" src=" + img_src1 + " align=middle>&nbsp;<label id=\"Lable1\"  style=\"cursor:pointer\" onclick=\"tog(this,'#ffffff');var sTemp = '"+trees[k].ID+"'; SpreadNextOrgTree(sTemp,'" + trees[k].ChildNumber +"'); \" >" + trees[k].Name + "</label>&nbsp;&nbsp;<input type=\"checkbox\" name=\"DeptCK\" onclick=\"ClearItem();var sTemp = '"+trees[k].ID +"'; GetNextOrgID(sTemp);\" value=\"" + trees[k].ID + "," + trees[k].Name + "\" /></td></tr></table>");
      document.write ("<span id='T" + trees[k].ID + "' style='display:none'>" );
      if(trees[k].ChildNumber != "0")
        show_tree(space_c +1 ,trees[k].ID);
      document.write ("</span>");
    }
  }
}


function ClearItem()
{
    GNextOrgID = "";    
}

function GetNextOrgID(OrgID)   //取得同级及下级部门ID的集合.为选择人员做准备
{
  var k;
  GNextOrgID = GNextOrgID + OrgID+",";
  for(k=0;k<trees.length;k++)
  {
    var TempStr = "";
    if(trees[k].ParentID == OrgID)   //当前组织的ID
    {
      TempStr = TempStr + trees[k].ID + ",";
      GetNextOrgID(trees[k].ID);
      GNextOrgID = GNextOrgID + TempStr ;
    }
  }
}

//去掉重复的数据
function DelRepeatData(sData)
{
   ClearItem();
   var ary = sData.split(',');
   var iary = ary.length;
   for(i=0;i<ary.length;i++)
   {
       var itype = 0;
       for (j=i+1;j<ary.length;j++)
       {
          if(ary[i] ==ary[j])
          {
            itype =1;
            break;
          }
       }
       if(itype == 0 && i!= iary-1)
       {
         GNextOrgID = GNextOrgID + ary[i] + ",";
       }
       else
       {
         itype =0;
       }
   }   
}


//展开收缩下一级部门
function SpreadNextOrgTree(DeptID,ChildNum)
{
  var i,j,k,img_src1,img_src2;
  if(ChildNum!="0")
  {
    if(eval("document.all.T"+DeptID+".style.display")=='none')
    {
      eval("document.all.T"+DeptID+".style.display=''");    //展开下级层
      eval("document.all.img_"+DeptID+".src=\"img/sys/open.gif\";");    //展开下级层
      eval("document.all.img_"+DeptID+".lowsrc=\"img/sys/close.gif\";");    //展开下级层
    }
    else
    {
      eval("document.all.T"+DeptID+".style.display='none'");    //收缩下级层
      eval("document.all.img_"+DeptID+".src=\"img/sys/close.gif\";");    //收缩下级层
      eval("document.all.img_"+DeptID+".lowsrc=\"img/sys/open.gif\";");    //收缩下级层
    }
  }
}

function GetSuperOrgID(OrgID)   //取得上级部门ID的集合.为展开树做准备的.
{
  var k;
  for(k=0;k<trees.length;k++)
  {
    var TempStr = "";
    if(trees[k].ID == OrgID)   //当前组织的ID
    {
      TempStr = TempStr + trees[k].ID + ",";
      GetSuperOrgID(trees[k].ParentID);
      GOrgInfo = GOrgInfo + TempStr ;
    }
  }
  //hidform.hOrgInfo1.value =  GOrgInfo;
  //SpreadNewOrgTree();
}

//展开一个新树

function SpreadNewOrgTree()
{  
  var i,j,k,img_src1,img_src2;
      if(GOrgInfo!="")
      {
        var ary  = GOrgInfo.split(',');
        var nary = ary.length;
        for(i=0;i<nary-1;i++)
        {
          eval("document.all.T"+ary[i]+".style.display=''");
        } 
      }
      else
      {
        //alert(GOrgInfo);
      }
}

var tgs; 
var tmp_background_val; 
function tog(n,flags)
{ 
  if (tgs)
  { 
    tgs.style.background= tmp_background_val ; 
  } 
  n.style.background= '#99ccff'; 
  tmp_background_val=flags;
  tgs=n; 
} 
-->
    </script>
</head>
<body>
<% 
  Response .ExpiresAbsolute=System.DateTime.Now. AddSeconds(-1);
  Response.Expires=0;
  Response.CacheControl = "no-cache";
%>
<table align ="center" width="98%" cellpadding ="10" cellspacing ="0" >
 <tr>
   <td><%=sDeptHtml %></td>
 </tr>
</table>
<form id = "hidform" method="post" runat ="server">
 <table cellpadding ="0" style =" width :auto;" cellspacing ="0" border ="0">
   <tr>
    <td width="60"></td> 
    <td>
       <input type="button" id="ChoiceDeptID" value ="确定" class="button02" onclick ="AlreadyChoiceDeptInfo()" />&nbsp;&nbsp;
       <!--<input type="button" id="Button1" value ="返回" class="button02" onclick ="var obj = dialogArguments;window.returnValue = obj;window.close();" /> -->
    </td>
   </tr>
 </table>    
 <input type="hidden" id="hOrgInfo" runat ="server" />
 <input type="hidden" id="hOrgID" runat ="server" />
 <input type="hidden" id="hOrgName" runat ="server" />
 <input type="hidden" id="hParentOrgID" runat ="server" />
 <input type="hidden" id="hChildNumber" runat ="server" />
 <input type="hidden" id="hOrgIDCol" runat ="server" />
 <input type="hidden" id="hOrgType" runat ="server" />
 <input type="hidden" id="hChoiceID" runat ="server" />
</form>


<script language ="javascript" type ="text/javascript" >
<!--
    //网页对话框初始化信息
  var sData     = dialogArguments;  
  var sTemp     = sData.iTem;
  var sPageUserGroupInfo = hidform.hChoiceID.value ;
  
  var CompareOrgID  = eval("sData.form1.HChoiceUserGroupID_"+sPageUserGroupInfo+".value;");   //新建时显示的ID  
  
  var aaComAry = CompareOrgID.split('^');
  if(aaComAry.length >1)
  {
      var ComAry = aaComAry[1].split(',');
      var iComAry = ComAry.length;
      for(p=0;p<iComAry;p++)
      {
        var ComTemp = ComAry[p];
        GetSuperOrgID(ComTemp);            //得到CompareOrgID的所有上级ID
        SpreadNewOrgTree();                //展开此树
      
        if(trees.length == 1)         //只有一个部门时
        {
           var DeptValue = document.all.DeptCK.value;
           var DeptAry = DeptValue.split(',');
           if(DeptAry[0] == ComTemp)
           {
              document.all.DeptCK.checked = true;
              break;
           }  
        }
        else
        {
          for(j=0;j<trees.length;j++)
          {
             var DeptValue = document.all.DeptCK[j].value;
             var DeptAry = DeptValue.split(',');
             if(DeptAry[0] == ComTemp)
             {
                document.all.DeptCK[j].checked = true;
                break;
             }
           }
        }
      }
  }
  

//点击复选框事件
 function IFChoice(obj)
 {
    if(obj.checked)
    {
       AllChoice(GNextOrgID);
    }
    else
    {
       DelAllChoice(GNextOrgID);
    }
 }
 
 
 function AllChoice(OrgIDCol)
 {
   var i,x;
   var ary = OrgIDCol.split(',');
   var iary = ary.length;
   for(i = 0;i<iary-1;i++)
   {
     for(x=0;x<trees.length;x++)
     {
       var DeptValue = document.all.DeptCK[x].value;
       var DeptAry = DeptValue.split(',');
       if(DeptAry[0] == ary[i])
       {       
         document.all.DeptCK[x].checked = true;
         break;
       }
     }
   }
 }
 
 
 function DelAllChoice(OrgIDCol)
 {
   var i,x;
   var ary = OrgIDCol.split(',');
   var iary = ary.length;
   for(i = 0;i<iary-1;i++)
   {
     for(x=0;x<trees.length;x++)
     {
       var DeptValue = document.all.DeptCK[x].value;
       var DeptAry = DeptValue.split(',');
       if(DeptAry[0] == ary[i])
       {
         document.all.DeptCK[x].checked = false;
         break;
       }
     }
   }
 }
 
 //全部取消已选定当前部门及其下级部门
 function AlreadyChoiceDeptInfo()
 {
   var x;
   var sDeptInfoCol = "";
   if(trees.length == 1)
   {        
     if(document.all.DeptCK.checked == true)
     {
       sDeptInfoCol = sDeptInfoCol + document.all.DeptCK.value + "|";
     }
   }
   else
   {
     for(x=0;x<trees.length;x++)
     {     
       if(document.all.DeptCK[x].checked == true)
       {
         sDeptInfoCol = sDeptInfoCol + document.all.DeptCK[x].value + "|";
       }
     }
   }
      var obj         = dialogArguments;
      var sTemp       = obj.iTem;      
      var sChoiceID = hidform.hChoiceID.value;
      var iChoiceNum  =  eval("obj.iChoiceUserGroupNumber"+sChoiceID);
      var DeptNum = sDeptInfoCol.split('|'); 
      var UserGroupID = "";
      var UserGroupName = "";     
      var iDeptNum = DeptNum.length;
      for(i=0;i<iDeptNum-1;i++)
      {
         var aUserGroupNameID = DeptNum[i].split(',');
         UserGroupID   = UserGroupID + aUserGroupNameID[0];
         UserGroupName = UserGroupName + aUserGroupNameID[1];
         if(i!= iDeptNum-2)
         {
             UserGroupID   = UserGroupID +"," ;
             UserGroupName = UserGroupName + ",";
         }
      }
      
      if(isNaN(iChoiceNum))
	  {
	      alert("操作错误,重新进入");
          return;
	  }
      if( iChoiceNum != "0")
      {
         if(iDeptNum-1 > iChoiceNum)
         {          
            alert("您选择的信息超过"+iChoiceNum+"个");
            return;
         }
      }
      var sPageUserGroupInfo = hidform.hChoiceID.value ;
      var ChoiceUserGroupNameInfo = "\"" + UserGroupName  + "\"" ;
      var ChoiceUserGroupIDInfo = "\"" + sPageUserGroupInfo + "^" + UserGroupID  + "\"" ;            
      obj.sPageUserGroupInfo = sPageUserGroupInfo;
      obj.ChoiceUserGroupNameInfo = ChoiceUserGroupNameInfo;
      obj.ChoiceUserGroupIDInfo = ChoiceUserGroupIDInfo;
      window.returnValue = obj;
      window.close();
   }
   
   //关闭窗口事件
  /* function window.onunload()
   {
      AlreadyChoiceDeptInfo();
   }*/
 //} 
 -->
</script>     
</body>
</html>